﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace syh876.com.ajax.Account
{
    /// <summary>
    /// Register 的摘要说明
    /// </summary>
    public class Register : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            string _isCheck = Common.RequestHelper.GetString("cbAllow");//是否同意协议内容
            string Name = Common.RequestHelper.GetFormString("txtName").Trim();
            string Pwd = Common.RequestHelper.GetFormString("txtPwd").Trim();
            string Email = Common.RequestHelper.GetFormString("txtEmail").Trim();
            //string code = Common.RequestHelper.GetFormString("txtCode").Trim();
            string QQ = Common.RequestHelper.GetFormString("txtQQ").Trim();
            string _ip = Common.RequestHelper.GetIP();//获取当前用户的ip
            string cbAllow = Common.RequestHelper.GetFormString("cbAllow").Trim();
            Common.CookieHelper.DelCookies("CheckCode");    //清除cookie
            string JsonP = Common.RequestHelper.GetString("callback");

            string txtRealName = Common.RequestHelper.GetFormString("txtRealName").Trim();
            string txtCompName = Common.RequestHelper.GetFormString("txtCompName").Trim();
            string txtMobile = Common.RequestHelper.GetFormString("txtMobile").Trim();
            int industryId = Common.RequestHelper.GetFormInt("selecthangye", 0);
            int sex = Common.RequestHelper.GetFormInt("_sex", 0);
            int shenfen = Common.RequestHelper.GetFormInt("_shenfen", 0);
            string[] arraydic = Common.RequestHelper.GetFormString("_DistrictStr").Split(',');

            SYH.User.Model.UserSimplyInfo model = new SYH.User.Model.UserSimplyInfo();
            model.Name = Name;
            model.Password = Common.MD5.Md5En(Pwd);
            model.Nature = 0;//默认值
            model.Email = Email;
            model.Ip = Common.RequestHelper.GetIP();
            model.QQ = QQ;         
            model.CompanyName = txtCompName;
            model.LinkMan = txtRealName;
            model.Mobile = txtMobile;
            model.ProvinceId = Convert.ToInt32(arraydic[0]);
            model.CityId = Convert.ToInt32(arraydic[1]);
            model.AreaId = Convert.ToInt32(arraydic[2]);
            model.Sex = sex;
            model.Nature = shenfen;
            model.IndustryId = industryId;
            if (_isCheck == "2")
            {
                
                    //string cookiecode = Common.CookieHelper.GetCookie("CheckCode");
                    int ID = SYH.User.BLL.UserSimplyInfo.AddUser(model);
                    //com.qihuiwang.api.WebMessageService a = new com.qihuiwang.api.WebMessageService();
                    //a.MessageAdd("系统消息", "", ID, (Int32)QHWShop.Enum.WebMessageType.注册成功);
                    if (ID > 0)
                    {
                        context.Response.Write(JsonP + "({\"Msg\":\"" + ID + "\"})");
                        context.Response.End();
                    }
                    else
                    {
                        context.Response.Write(JsonP + "({\"Msg\":\"" + "注册失败" + "\"})");//失败
                        context.Response.End();
                    }
              
            }
            else
            {
                context.Response.Write(JsonP + "({\"Msg\":\"" + "请先选择同意《生意汇服务条款》" + "\"})");//输入格式不正确
                context.Response.End();
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}